package main

import "fmt"

type window struct {
    s int   //start
    e int   //end
    w int   //width
}

func main() {
    s := "abcabcdbbabcdefbfcabdcf"
    b := []byte(s)
    win := window{0, 0, 2}
    result := win
    m := make(map[byte]int, 28)
    max := 0
    var tmp = []byte{}
    fmt.Println(string(tmp))

    for {
        ei := b[win.e]
        si := b[win.s]

        if m[ei] == 0 {
            tmp = append(tmp, ei)
            m[ei] = win.e + 1
            win.e++

            if max < len(tmp) {
                max = len(tmp)
                result = win
            }
        } else {
            tmp = tmp[1:]
            m[si] = 0
            win.s++
        }
        if win.e >= len(b) {
            break
        }
        fmt.Printf("%s, max = %d, pos %c,  %d-%d\n", string(tmp), max, b[win.e], win.s, win.e)
    }
    fmt.Println(max)
    fmt.Println(string(b[result.s:result.e]))
}
